#include "stdafx.h"
#include "MagicDamage.h"
#include "SkillAdditionInfo.h"
#include "LogProc.h"
#include "Gamemain.h"
#include "..\include\ReadScript.h"

CSkillAdditionInfo	g_SkillAdditionInfo;

//004c6850	-> 100%
CSkillAdditionInfo::CSkillAdditionInfo()
{
	this->Init();
}

//004c68d0	-> 100%
CSkillAdditionInfo::~CSkillAdditionInfo()
{
	return;
}

//004c6900	-> 100%
void CSkillAdditionInfo::Init()
{
	this->m_iInfinityArrowSkillTime				= 0;
	this->m_iInfinityArrowUseLevel				= 0;
	this->m_iInfinityArrowMPConsumptionPlus0	= 0;
	this->m_iInfinityArrowMPConsumptionPlus1	= 0;
	this->m_iInfinityArrowMPConsumptionPlus2	= 0;
	this->m_iInfinityArrowMPConsumptionPlus3	= 0;

	for(int i = 0; i <= 5; i++)	//wz mistake
	{
		this->m_nSoulBarrierManaRate_Level[i] = 0;
	}

#ifdef __CUSTOMS__
	ZeroMemory(this->m_SkillUseReqLevel, sizeof(m_SkillUseReqLevel));
#endif
}

//004c69a0	-> 100%
int CSkillAdditionInfo::Load(LPSTR lpszFileName)
{
	if (lpszFileName == NULL || strcmp(lpszFileName, "") == 0)
	{
		LogAddTD("[Skill Addition Info] - File load error : File Name Error");
		return false;
	}

#ifdef __CUSTOMS__
	int Token;
	this->Init();
	SMDFile = fopen(gDirPath.GetNewPath(lpszFileName), "r");

	if (SMDFile == 0)
	{
		MsgBox(lMsg.Get(MSGGET(0, 112)), lpszFileName);
		return false;
	}

	while (true)
	{
		Token = GetToken();

		if (Token == END || !strcmp(TokenString, "end"))
		{
			break;
		}
		else
		{
			int SkillID = TokenNumber;
			Token = GetToken();
			int Level	= TokenNumber;

			if (Level < 1)
			{
				Level = 1;
			}

			this->m_SkillUseReqLevel[SkillID] = Level;
		}
	}

	fclose(SMDFile);
#endif
	this->m_iInfinityArrowSkillTime				= GetPrivateProfileInt("SkillInfo", "InfinityArrowSkillTime", 600, gDirPath.GetNewPath(lpszFileName));
	this->m_iInfinityArrowUseLevel				= GetPrivateProfileInt("SkillInfo", "InfinityArrowUseLevel", 220, gDirPath.GetNewPath(lpszFileName));
	this->m_iInfinityArrowMPConsumptionPlus0	= GetPrivateProfileInt("SkillInfo", "InfinityArraowMPConsumptionPlus0", 0, gDirPath.GetNewPath(lpszFileName));
	this->m_iInfinityArrowMPConsumptionPlus1	= GetPrivateProfileInt("SkillInfo", "InfinityArraowMPConsumptionPlus1", 0, gDirPath.GetNewPath(lpszFileName));
	this->m_iInfinityArrowMPConsumptionPlus2	= GetPrivateProfileInt("SkillInfo", "InfinityArraowMPConsumptionPlus2", 0, gDirPath.GetNewPath(lpszFileName));
	this->m_iInfinityArrowMPConsumptionPlus3	= GetPrivateProfileInt("SkillInfo", "InfinityArraowMPConsumptionPlus3", 0, gDirPath.GetNewPath(lpszFileName));
	LogAddTD("[Skill Addition Info] [Infinity Arrow] Skill Time[%d], UseLevel[%d], Arrow MP Consumption +0[%d] +1[%d] +2[%d] +3[%d]", this->m_iInfinityArrowSkillTime, this->m_iInfinityArrowUseLevel, this->m_iInfinityArrowMPConsumptionPlus0, this->m_iInfinityArrowMPConsumptionPlus1, this->m_iInfinityArrowMPConsumptionPlus2, this->m_iInfinityArrowMPConsumptionPlus3);
	this->m_bFireScreamSkill					= GetPrivateProfileInt("SkillInfo", "FireScreamSkill", 1, gDirPath.GetNewPath(lpszFileName));
	this->m_iFireScreamExplosionAttackDistance	= GetPrivateProfileInt("SkillInfo", "FireScreamExplosionAttackDistance", 1, gDirPath.GetNewPath(lpszFileName));
	this->m_iFireScreamExplosionRate			= GetPrivateProfileInt("SkillInfo", "FireScreamExplosionRate", 300, gDirPath.GetNewPath(lpszFileName));
	this->m_iFireScreamMaxAttackCountSameSerial = GetPrivateProfileInt("SkillInfo", "FireScreamMaxAttackCountSameSerial", 3, gDirPath.GetNewPath(lpszFileName));
	this->m_iFireScreamSerialInitCount			= GetPrivateProfileInt("SkillInfo", "FireScreamSerialInitCount", 100, gDirPath.GetNewPath(lpszFileName));
	this->m_bCheckFireScreamSerial				= GetPrivateProfileInt("SkillInfo", "CheckFireScreamSerial", 1, gDirPath.GetNewPath(lpszFileName));
	LogAddTD("[Skill Addition Info] [Fire Scream] Use(%d) : Explosion Distance(%d) - Rate(%d), MaxAttack_SameSerial(%d), SerialInitCount(%d), Check Serial(%d)", this->m_bFireScreamSkill, this->m_iFireScreamExplosionAttackDistance, this->m_iFireScreamExplosionRate, this->m_iFireScreamMaxAttackCountSameSerial, this->m_iFireScreamSerialInitCount, this->m_bCheckFireScreamSerial);
	char szTemp[63]		= { 0 };
	BYTE byDefault		= 0;
	int n				= 1;

	for(n = 1; n < 21; n++)
	{
		wsprintf(szTemp, "SoulBarrierManaRate_Level%d", n);
		byDefault = 20 + n;
		this->m_nSoulBarrierManaRate_Level[n] = GetPrivateProfileInt("SkillInfo", szTemp, byDefault, gDirPath.GetNewPath(lpszFileName));
	}

	char szTempLog[511]	= { 0 };
	wsprintf(szTempLog, "[Skill Addition Info] [SoulBarrier Strengrhen] BaseSkill (Level0):%d", this->m_nSoulBarrierManaRate_Level[0]);

	for(n = 1; n < 21; n++)
	{
		wsprintf(szTemp, ", Level%d : %d", n, this->m_nSoulBarrierManaRate_Level[n]);
		strcat(szTempLog, szTemp);
	}

	LogAddTD(szTempLog);
	return true;
}

//004c6eb0	-> 100%
short CSkillAdditionInfo::GetSoulBarrierManaRate_Level(int iLevel)
{
	if (iLevel < 0 || iLevel > 20)	//increased (from 5 to 20) by 1.1.0.0
	{
		return 20;
	}

	return this->m_nSoulBarrierManaRate_Level[iLevel];
}